import { Transform } from 'class-transformer';
import { IsOptional, IsString } from 'class-validator';
import * as dayjs from 'dayjs';

export class TrackListModel {
  @Transform(({ value }) => parseInt(value, 10))
  pageSize: number;
  @Transform(({ value }) => parseInt(value, 10))
  pageIndex: number;

  @IsOptional() // 使 createdAt 可选
  @Transform(({ value }) => {
    if (!value) {
      return undefined;
    }
    return dayjs(value).toISOString();
  })
  createdAt?: Date;
  @IsString()
  @IsOptional() // 使 createdAt 可选
  name?: string;

  constructor() {
    this.pageIndex = 1;
    this.pageSize = 10;
  }
}
